package com.xyy.saas.payment.cores.enums;

import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * @author liujf
 */
@Getter
public enum XydTradeTypeEnum {
    PRE_PAY_RECHARGE(14, "预付款充值"),
    GUARANTEE_GOLD_RECHARGE(16, "保证金充值"),
    GUARANTEE_GAP_RECHARGE(17, "保证金缺口充值"),
    DAILY_REPAY(23, "日常还款"),
    ON_TIME_REPAY(24, "按期还款"),
    PART_PRE_REPAY(25, "部分提前还款"),
    PRE_ALL_SETTLE(26, "提前全额结清"),
    REFUND(27, "退货"),
    REPURCHASE(28, "回购"),
    COMPENSATION(29, "代偿"),
    CASH_SETTLE_REFUND(46, "资金结算退款"),
    REMEMBER_RECHARGE(52, "记账宝充值"),
    TRANSFER(54, "转账"),
    ;
    private Integer code;

    private String name;

    private static Map<Integer, XydTradeTypeEnum> codeCache = new HashMap<>();
    static {
        for (XydTradeTypeEnum tradeTypeEnum : values()) {
            codeCache.put(tradeTypeEnum.getCode(), tradeTypeEnum);
        }
    }

    XydTradeTypeEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public static String getNameByCode(Integer code) {
        XydTradeTypeEnum anEnum = codeCache.get(code);
        if (anEnum != null) {
            return anEnum.getName();
        }
        return null;
    }
}
